/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.ove.openmath.jome.ctrl.amto;

/**
 *
 * @author Mr.Sam
 */
import fr.ove.openmath.jome.ctrl.linear.events.LinearParserEvent;
import fr.ove.openmath.jome.ctrl.amto.Function;

/**
* The abstract math tree object of operators looking like : <BR>
* <OMA> <OMS ..../> <OMBIND>.....</OMBIND> </OMA>.
* <P>
* Among them we can find integral, differentiation, ....
*
* @author © 2000 DIRAT Laurent
* @version 1.0  23/02/2000
*/
public class MapsToSymbolBind extends Function {
    /**
    * The constructor.
    */
    public MapsToSymbolBind() {
        super("maps2SymbolBind");
    }
    
    /**
    * "Flushes" the object as a sequence of events for the building of the model
    */
    public void flush() {
        LinearParserEvent linearParserEvent = new LinearParserEvent(getEventSource());
        
        // The opening
        linearParserEvent.setToken(opening, param);
        fireLinearParserEvent(linearParserEvent);
        
        // the child of the instance should be either a bind or another differentiation
        AbstractMathTreeObject child = (AbstractMathTreeObject) getChild(0);
        String childId = child.identifier;
        if (childId.equals("lambda")) {
            int nbChildren = child.getNbChildren();
            int count = nbChildren - 1;
            flushChild(child.getChild(count), count);
            for (int i = 0; i < count; i++) {
                linearParserEvent.setToken(token, null);
                fireLinearParserEvent(linearParserEvent);
                flushChild(child.getChild(i), i);
            }
        }
        
        // The closing
        linearParserEvent.setToken(closing, null);
        fireLinearParserEvent(linearParserEvent);
    }
}